define(function(require, exports, module) {
    
    var rk = require('rk');
    var tplTabs = require('page/tmpl/search/searchresult.tpl');

    
    var defaultPageNo = 1;
    var defaultPageSize = 20;
    
    
    require('oldcrm/js/apps/account/acc.detail');
    require('oldcrm/js/apps/opportunity/opp.detail');
    require('oldcrm/js/apps/contact/contact.detail');
    require('oldcrm/js/apps/agent/agent.detail');
    require('oldcrm/js/apps/terminal/terminal.detail');
    require('oldcrm/js/apps/lead/lead.detail');
    require('oldcrm/js/apps/partner/partner.detail');

    var messageCount = 0;
    var fileCount = 0;
    var blogCount = 0;
    var praiseCount = 0;
    var questionCount = 0;

    var nameMap = {
        message: 'dynamic_message',
        document: "dynamic_file",
        blog: "dynamic_blog",
        praise: "dynamic_praise",
        answer: "dynamic_question"
    }

    function processFullTextSetting(me) {

        var fullTextRetrievalSettingStr = me.data.fullTextRetrievalSetting;
        if (fullTextRetrievalSettingStr) {
            me.data.setting = {};
            var fullTextRetrievalSetting = JSON.parse(fullTextRetrievalSettingStr);
            var haveCrmData = false;
            var haveDynamicData = false;
            var haveTopicData = false;
            for (var key in fullTextRetrievalSetting.crm) {
                if (fullTextRetrievalSetting.crm[key] == 1) {
                    haveCrmData = true;
                    break;
                }
            }

            var itemArray = [];
            for (var key in fullTextRetrievalSetting.dynamic) {
                if (key == 'topic' && fullTextRetrievalSetting.dynamic[key] == 1) {
                    haveTopicData = true;
                } else if (fullTextRetrievalSetting.dynamic[key] == 1) {
                    itemArray.push(nameMap[key]);
                    haveDynamicData = true;
                }
            }

            if (haveCrmData) {
                me.haveCrmData = true;
                me.data.setting.crm = fullTextRetrievalSetting.crm;
            }

            if (haveDynamicData) {
                me.haveDynamicData = true;
                me.dynamicItems = itemArray;
                me.data.setting.dynamic = fullTextRetrievalSetting.dynamic;
            }

            if (haveTopicData) {
                me.haveTopicData = true;
                me.data.setting.topic = fullTextRetrievalSetting.dynamic.topic;
            }
        }
    }

    function getCrmDefaultTabByParentTabAndSetting(parentTab, setting) {
        var defaultTabName = "";
        if (parentTab == 'crm') {
            //没有设置检索范围的情况
            if (!setting) {
                if (SESSION.tenantType == 1) {
                    defaultTabName = "agent";
                } else {
                    defaultTabName = "account";
                }
            } else if (setting.crm.agent) {
                defaultTabName = "agent";
            } else if (setting.crm.account) {
                defaultTabName = 'account';
            } else if (setting.crm.agent) {
                defaultTabName = "agent";
            } else if (setting.crm.opportunity) {
                defaultTabName = 'opportunity';
            } else if (setting.crm.lead) {
                defaultTabName = 'lead';
            } else if (setting.crm.contact) {
                defaultTabName = 'contact';
            } else if (setting.crm.partner) {
                defaultTabName = 'partner';
            }

        } else if (parentTab == 'dynamic') {
            //没有设置检索范围的情况
            if (!setting) {
                defaultTabName = "dynamic_message";
            } else if (setting.dynamic.message) {
                defaultTabName = "dynamic_message";
            } else if (setting.dynamic.document) {
                defaultTabName = "dynamic_file";
            } else if (setting.dynamic.blog) {
                defaultTabName = "dynamic_blog";
            } else if (setting.dynamic.praise) {
                defaultTabName = "dynamic_praise";
            } else if (setting.dynamic.answer) {
                defaultTabName = "dynamic_question";
            }
        } else if (parentTab == 'topic') {
            defaultTabName = 'topic';
        }
        return defaultTabName;
    }




    $.widget('rk.searchresultCtrl', {
        _create: function() {
            var me = this,
                elem = this.element;
            //me._listeners();

        },
        /*_listeners:function(){
            var me = this,
                elem = this.element;
            var keyword = decodeURIComponent($.query('keyword'));
        },*/
        _init: function() {
            var me = this;

            //进入本页入口调用
            me._loaddataInit();
        },
        _loaddataInit: function() {
            var me = this,
                elem = this.element;
            //var opt = me.options;
            //var keyword = opt.keyword;
            var keyword = decodeURIComponent($.query('keyword'));
            var parentTabName = "";
            var defaultTabName = "";

            rk.post("/json/crm_search/all.action", {
                getCrmRight: "1"
            }, function(json) {
                if (json.status == 0) {
                    me.data = json.data;
                    me.data.key = keyword;
                    processFullTextSetting(me);

                    if (me.haveCrmData) {
                        parentTabName = "crm";
                    } else if (me.haveDynamicData) {
                        parentTabName = "dynamic";
                    } else if (me.haveTopicData) {
                        parentTabName = "topic";
                    }

                    var setting = me.data.setting;
                    defaultTabName = getCrmDefaultTabByParentTabAndSetting(parentTabName, setting);

                    me._fillParentTab(me, defaultTabName, parentTabName);

                    var map = {
                        yj: 'join.action',
                        yf: 'follow.action',
                        nj: 'quit.action',
                        nf: 'unfollow.action'
                    };

                    elem.on('click', '[act="act_attention"]', function(evt) {
                        evt.preventDefault();
                        var $lnk = $(this),
                            type = $lnk.attr('type'),
                            groupId = $lnk.attr('groupid'),
                            isAdd = $lnk.hasClass('no_follow') ? 'y' : 'n',
                            key = isAdd + type;
                        $.post('/json/sns_group/' + map[key], {
                            groupId: groupId
                        }, null, 'json').done(function(json) {
                            if (json.status == 0) {
                                //isAdd == 'y' ? $lnk.attr('title', '取消关注').removeClass('no_follow').addClass('has_follow') : $lnk.attr('title', '加关注').removeClass('has_follow').addClass('no_follow');
                                isAdd == 'y' ? $lnk.attr('title', rk.i18n('CANCEL_INTEREST')).removeClass('no_follow').addClass('has_follow') : $lnk.attr('title', rk.i18n('PLUS_INTEREST')).removeClass('has_follow').addClass('no_follow');
                            }
                        }).fail(function(def, code, file) {
                            def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                        });
                    });

                    elem.on('click', '[act="act_get"]', function (evt) {
                        evt.preventDefault();
                        var $lnk = $(this),
                            entityId = $lnk.attr('entityid'),
                            entityName = $lnk.attr('entityname'),
                            belongId = $lnk.attr('belongid');
                        var html = '<div class="pop_up_02"><div class="pop_up_content"><div class="add_new_list clear js-contentDiv" ><div class="field clear">' + entityName + '</div></div></div><div class="pop_up_bottom"><div class="pop_up_button"><a  title="" href="javascript:;" class="green_button js-btnClose" style="display: none;" act="close">' + rk.i18n('CRM_CORE_CLOSE') + '</a><a  title="" href="javascript:;" class="cancel js-btnConfirm" act="close">' + rk.i18n('CRM_CORE_CANCEL') + '</a> <a  title="" href="javascript:;" class="green_button js-btnConfirm" act="save">' + rk.i18n('CRM_CORE_CONFIRM') + '</a></div></div></div>';
                        var url = belongId == 1 ? '/json/crm_highsea/claim.action' : '/json/crm_leadhighsea/claim.action';
                        var param = (belongId == 1 ? {accountIds: entityId} : {leadIds: entityId});
                        me.$dialog = $(html);
                        me.$dialog.popup({
                            width: 520,
                            title: rk.i18n('HIGHSEA_12') + (belongId == 1 ? SESSION.keywords.account : SESSION.keywords.lead),
                            actions: {
                                save: function (evt, dialog) {
                                    var $lnk = $(this).loading();
                                    $.postJson(url, param).done(function (json) {
                                        if (json.status == 0) {
                                            var result = $.parseJSON(json.opreateResult);
                                            var count = $.parseJSON(json.resultCount);
                                            me.$dialog.find(".js-btnConfirm").hide();
                                            me.$dialog.find(".js-btnClose").show();
                                            me.$dialog.find(".js-contentDiv").html('<ul class="pop_list pop_list_title js-ul" id="ul"><li><span>' + rk.i18n('HIGHSEA_20') + '：</span><span>' + count.all + '</span><span style="margin-left:20px;">' + rk.i18n('CRM_CORE_SUCCESS') + '：</span><span>' + count.success + '</span><span style="margin-left:20px;">' + rk.i18n('CRM_CORE_FAILED') + '：</span><span>' + count.failed + '</span></li></ul>');
                                            for (var i = 0; i < result.length; i++) {
                                                me.$dialog.find(".js-ul").append('<li><span>【' + rk.htmlEscape(result[i].name) + '】</span><span class="faild_reason">  "' + (result[i].message) + '"</span></li>');
                                            }
                                            me.$dialog.popup('refresh');
                                            if (count.failed == 0) {
                                                $('#tab-header').find('li.hover').find('a').trigger('click');
                                            }
                                        } else {
                                            $.msg(rk.i18n('HIGHSEA_12') + rk.i18n('CRM_CORE_FAILED'));
                                        }
                                    });
                                }
                            },
                            create: function () {
                            }
                        });
                    });

                    elem.on('click', '[act="act_allot"]', function (evt) {
                        evt.preventDefault();
                        var $lnk = $(this),
                            entityId = $lnk.attr('entityid'),
                            entityName = $lnk.attr('entityname'),
                            highSeaId = $lnk.attr('highseaid'),
                            belongId = $lnk.attr('belongid');

                        var html = '<div class="pop_up_02"><div class="pop_up_content"><div class="add_new_list exchge_group clear js-contentDiv" ><div class="field clear"><div class="field_name">' + rk.i18n('HIGHSEA_21') + '</div><div class="field_content"><input type="text" class="text" field="transferUser" placeholder="' + rk.i18n('CRM_CORE_INPUT_SELECT') + rk.i18n('CRM_CORE_IN_CHARGE') + '"></div></div></div></div><div class="pop_up_bottom"><div class="pop_up_button"><a  title="" href="javascript:;" class="green_button js-btnClose" style="display: none;" act="close">' + rk.i18n('CRM_CORE_CLOSE') + '</a><a href="javascript:;" act="close" class="cancel js-btnConfirm">' + rk.i18n('CRM_CORE_CANCEL') + '</a><a  title="" href="javascript:;" class="green_button js-btnConfirm" act="save">' + rk.i18n('CRM_CORE_CONFIRM') + '</a></div></div></div>';
                        me.$dialog = $(html);
                        var $input = me.$dialog.find('input[field=transferUser]');
                        me.$dialog.popup({
                            width: 520,
                            title: rk.i18n('HIGHSEA_24') + (belongId == 1 ? SESSION.keywords.account : SESSION.keywords.lead),
                            actions: {
                                save: function(evt, dialog) {
                                    var transferUserId = $input.attr('ownerId');
                                    if (transferUserId) {
                                        var $lnk = $(this).loading();
                                        var url = belongId == 1 ? '/json/crm_highsea/assign.action' : '/json/crm_leadhighsea/assign.action';
                                        var param = (belongId == 1 ? {
                                            accountIds: entityId,
                                            uid: transferUserId,
                                            highSeaId: highSeaId
                                        } : {leadIds: entityId, uid: transferUserId, leadHighSeaId: highSeaId});
                                        $.postJson(url, param).done(function (json) {
                                            if (json.status == 0) {
                                                var result = $.parseJSON(json.opreateResult);
                                                var count = $.parseJSON(json.resultCount);
                                                me.$dialog.find(".js-btnConfirm").hide();
                                                me.$dialog.find(".js-btnClose").show();
                                                me.$dialog.find(".js-contentDiv").html('<ul class="pop_list pop_list_title js-ul" id="ul"><li><span>' + rk.i18n('HIGHSEA_25') + '：</span><span>' + count.all + '</span><span style="margin-left:20px;">' + rk.i18n('CRM_CORE_SUCCESS') + '：</span><span>' + count.success + '</span><span style="margin-left:20px;">' + rk.i18n('CRM_CORE_FAILED') + '：</span><span>' + count.failed + '</span></li></ul>');
                                                for (var i = 0; i < result.length; i++) {
                                                    me.$dialog.find(".js-ul").append('<li><span>【' + rk.htmlEscape(result[i].name) + '】</span><span class="faild_reason">  "' + (result[i].message) + '"</span></li>');
                                                }
                                                me.$dialog.popup('refresh');
                                                if (count.failed == 0) {
                                                    $('#tab-header').find('li.hover').find('a').trigger('click');
                                                }
                                            } else {
                                                $lnk.loading('end');
                                                if (json.data && json.data.errorObjects) {
                                                    var msg = $.map(json.data.errorObjects, function (o) {
                                                        return [rk.i18n('HIGHSEA_25') + '【', o.name, '】' + rk.i18n('CRM_CORE_FAILED') + '：', o.message].join('');
                                                    }).join('<br/>');
                                                    $.msg(msg, false);
                                                } else {
                                                    $.msg(rk.i18n('HIGHSEA_25') + rk.i18n('CRM_CORE_FAILED'));
                                                }
                                            }
                                        });
                                    } else {
                                        $.msg(rk.i18n('ACCOUNT_SELECTED_TRANSFER_TO'));
                                    }
                                }
                            },
                            create: function() {
                                $input.autocomplete({
                                    minLength: 0,
                                    source: function (request, response) {
                                        var key = $.trim(request.term);
                                        $.postJson("/json/crm_search/all-users.action", {
                                            pageNo: 1,
                                            key: key
                                        }).done(function (data) {
                                            var id;
                                            if (data.length > 0) {
                                                $.each(data, function (i, d) {
                                                    if (d.value == key) {
                                                        id = d.id;
                                                    }
                                                });
                                            }
                                            id ? $input.attr('ownerId', id) : $input.removeAttr('ownerId');
                                            response(data);
                                        });
                                    },
                                    select: function (event, ui) {
                                        var id = ui.item.id;
                                        $input.attr('ownerId', id);
                                    }
                                });
                            }
                        });
                    });
                }
            }).fail(function(def, code, file) {
                def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
            });
        },

        _fillParentTab: function(me, tabName, parentTabName) {
            //填充父tab页
            var html = rk.templateText(tplTabs, {
                data: me.data,
                SESSION: SESSION
            });

            me.element.html(html);
            var isReloadTab = false;

            var parentTabs = [];
            if (me.data.crmPermission && me.haveCrmData) {
                parentTabs.push("crm");
            }
            if (me.haveDynamicData) {
                parentTabs.push("dynamic");
            }
            if (me.haveTopicData) {
                parentTabs.push("topic");
            }

            var activeNumber = parentTabs.indexOf(parentTabName) - 1;
            /*if(parentTabName == "dynamic"){
                activeNumber = 0;
            } else if(parentTabName == "topic"){
                activeNumber = 1;
            }*/

            var fnActivate = function(evt, ui, evtType) {
                var curTab = evtType == 'create' ? ui.tab : ui.newTab,
                    parentTab = curTab.attr('parentTabName');
                if (!curTab.data('inited')) {
                    var defaultTabName = getCrmDefaultTabByParentTabAndSetting(parentTab, me.data.setting);
                    var keyword = me.data.key;

                    //根据parenttab的切换加载该tab的数据
                    me._fillPanelData(defaultTabName, keyword, parentTab, ui);

                    if (parentTab == "crm") {
                        //crm小tab商机、客户等tab页切换
                        var clickTabName = "";
                        me.element.on('click', '[act="search_tab_crm_tab"]', function(evt) {
                            var button = $(this);
                            //if (clickTabName == button.attr('tabName')) return;
                            evt.preventDefault();
                            //                                $(this).beLoading({size: 'large'})//显示大号的loading

                            me.element.find('.fuzzy_result_div').eq(0).html = "";
                            me.element.find('.fuzzy_result_div').eq(0).beLoading({
                                    size: 'large'
                                }) //显示大号的loading

                            me._fillPanelData(button.attr('tabName'), keyword, "crm", ui);
                            clickTabName = button.attr('tabName');
                        })
                    } else if (parentTab == "dynamic") {
                        //crm小tab消息、文档等tab页切换
                        me.element.on('click', '[act="dynamic_tab"]', function(evt) {
                            evt.preventDefault();
                            var button = $(this);
                            me._fillPanelData(button.attr('tabName'), keyword, parentTab, ui);
                        })
                    }
                }
            };

            //给大tab设置切换事件
            $("#global-search—tabs").tabs(parentTabs.length > 1 ? {
                active: activeNumber,
                activate: function(evt, ui) {
                    // ui.newTab, ui.oldTab, ui.newPanel, ui.oldPanel
                    fnActivate(evt, ui, 'activate')
                }
            } : {
                active: activeNumber,
                create: function(evt, ui) {
                    // ui.tab, ui.panel
                    fnActivate(evt, ui, 'create')
                }
            });

            //如果有crm权限，输出3个页签，否则输出后面2个
            //$("#global-search—tabs").tabs('option', 'active', true);

            $("#global-search—tabs").tabs('option', 'active', parentTabs.indexOf(parentTabName));
            /* if (me.data.crmPermission == 1) {
                 if (parentTabName == "crm")
                     $("#global-search—tabs").tabs('option', 'active', 0);
                 else if (parentTabName == "dynamic")
                     $("#global-search—tabs").tabs('option', 'active', 1);
                 else if (parentTabName == "topic")
                     $("#global-search—tabs").tabs('option', 'active', 2);
             } else {
                 if (parentTabName == "dynamic")
                     $("#global-search—tabs").tabs('option', 'active', 0);
                 else if (parentTabName == "topic")
                     $("#global-search—tabs").tabs('option', 'active', 1);
             }*/

            //搜索结果重定向
            me.$input = me.element.find('input');
            me.$lnk = me.element.find('a');
            me.$input.on('keypress', function(evt) {
                evt.keyCode == 13 && me.$lnk.trigger('click');
            });
            me.$lnk.on('click', function(evt) {
                var act = $(this).attr("act");
                if (act == "search_btn") {
                    evt.preventDefault();
                    var keyword = $.trim(me.$input.val());
                    if (keyword) {
                        window.location.href = '/search.action?parentTabName=crm&keyword=' + encodeURIComponent(keyword);
                    } else {
                        $.msg(rk.i18n('ALLSEARCH_INPUT_CONTENT'));
                    }
                }
            });

            //分页信息
            /*me.element.find('[act="all_search_query_page_div"]').rkPaging({
             pagenum: me.data.pageNo,  //（可选）当前页数，默认1
             pagesize: me.data.pageSize,  //（可选）当前每页显示条数，默认10
             rowscount: me.data.totalCount, //所有数据数
             onChange: function (pagenum) {
             me._loaddataInit(me.data.key, pagenum, me.data.pageSize, me.data.parentTabName, tabName);
             }
             });*/
        },

        _fillPanelData: function(tabName, keyword, parentTabName, ui, pageNo, pageSize) {
            var me = this,
                elem = this.element,
                uiTab = ui.newTab || ui.tab,
                uiPanel = ui.newPanel || ui.panel;

            if (parentTabName == "topic") {
                //填充动态
                pageNo = defaultPageNo;
                pageSize = 20;
                me._loadtopicdata(uiTab, uiPanel, keyword, pageNo, pageSize, tabName, parentTabName);

                //elem.find('[act="all_search_query_page_div"]').hide();
                return;
            } else if (parentTabName == "dynamic") {
                //填充话题
                pageNo = defaultPageNo;
                pageSize = 20;
                me._loaddynamicdata(uiTab, uiPanel, keyword, pageNo, pageSize, tabName, parentTabName);

                var tabArr = me.dynamicItems ? me.dynamicItems : new Array("dynamic_message", "dynamic_file", "dynamic_blog", "dynamic_praise", "dynamic_question");
                for (var i in tabArr) {
                    var curTab = me.element.find("[act='" + tabArr[i] + "']");
                    if (tabArr[i] == tabName) {
                        if (!curTab.hasClass("hover"))
                            curTab.addClass("hover");
                    } else {
                        if (curTab.hasClass("hover"))
                            curTab.removeClass("hover");
                    }
                }

                //elem.find('[act="all_search_query_page_div"]').hide();
                return;
            } else if (parentTabName == "crm") {
                //elem.find('[act="all_search_query_page_div"]').show();
                $.postJson('/json/crm_search/all.action', {
                    key: keyword,
                    pageNo: pageNo || defaultPageNo,
                    pageSize: pageSize || defaultPageSize,
                    tabName: tabName,
                    parentTabName: parentTabName || "crm"
                }).done(function(json) {
                    if (json.status == 0) {
                        var data = json.data;
                        data.key = keyword;
                        //数据格式化
                        me._dataFormatBeforeShow(data, tabName);
                        //填充大tab内容
                        me._loadcrmdata(uiTab, uiPanel, data);

                        if (parentTabName == "crm") {
                            var tabArr = new Array("opportunity", "contact", "account", "lead", "partner");
                            //for (var i in tabArr) {
                            //var curTab = me.element.find("[act='" + tabArr[i] + "_li']");
                            //if (tabArr[i] == tabName) {
                            //    if (!curTab.hasClass("hover"))
                            //        curTab.addClass("hover");
                            //} else {
                            //    if (curTab.hasClass("hover"))
                            //        curTab.removeClass("hover");
                            //}
                            //}
                            elem.find("[tabNameSearch='crm']").removeClass("hover");
                            elem.find("[act='" + tabName + "_li']").addClass("hover");
                            //设置详情页拉出连接
                            if (SESSION.tenantType == 1) {
                                if (tabName == "contact") {
                                    uiPanel.detailPopupRn2({
                                        widgetName: 'contactDetail',
                                        selector: 'a.js_contact_name',
                                        target: '#div_detail_frame_third'
                                    }).showRecentAct({});

                                    $('#div_detail_frame_third').editable({
                                        isDigHole: true
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame_third').simpleTabs('refresh');
                                        }
                                    }).deleteContact().addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_third div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_third div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTeamMember();
                                } else if (tabName == "agent") {
                                    uiPanel.detailPopup({
                                        widgetName: 'agentDetail',
                                        selector: 'a.js_agent_name',
                                        target: '#div_detail_frame'
                                    }).showRecentAct({});

                                    $('body').createOpportunity().createLead().createAccount().createContact().editBusiness().createContract().createCampaign().createCustomize().createOrder().createCase();

                                    $('#div_detail_frame').editable({
                                        isDigHole: true
                                    }).addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame').simpleTabs('refresh');
                                        }
                                    }).addTeamMember();
                                } else if (tabName == "terminal") {
                                    uiPanel.detailPopupRn3({
                                        widgetName: 'terminalDetail',
                                        selector: 'a.js_terminal_name',
                                        target: '#div_detail_frame_second'
                                    }).showRecentAct({});

                                    $('body').createOpportunity().createLead().createAccount().createContact().editBusiness().createContract().createCampaign().createCustomize().createOrder().createCase();

                                    $('#div_detail_frame_second').editable({
                                        isDigHole: true
                                    }).addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame_second').simpleTabs('refresh');
                                        }
                                    }).addTeamMember();
                                }
                            } else {
                                if (tabName == "account") {
                                    uiPanel.detailPopup({
                                        widgetName: 'customerDetail',
                                        selector: 'a.js_customer_name',
                                        target: '#div_detail_frame'
                                    }).showRecentAct({});

                                    $('body').createOpportunity().createLead().createAccount().createContact().editBusiness().createContract().createCampaign().createCustomize().createOrder().createCase();

                                    $('#div_detail_frame').editable({
                                        isDigHole: true
                                    }).addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame').simpleTabs('refresh');
                                        }
                                    }).addTeamMember();
                                } else if (tabName == "opportunity") {
                                    uiPanel.detailPopupRn({
                                        widgetName: 'opportunityDetail',
                                        selector: 'a.js_opp_name',
                                        target: '#div_detail_frame_second'
                                    }).showRecentAct({});

                                    $('#div_detail_frame_second').editable({
                                        isDigHole: true
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame_second').simpleTabs('refresh');
                                        }
                                    }).addTeamMember().addContact({
                                        onSuccess: function() {
                                            $('#div_detail_frame_second').simpleTabs('refresh', 2);
                                        }
                                    }).addProduct({
                                        onSuccess: function() {
                                            $('#div_detail_frame_second').simpleTabs('refresh', 4);
                                        }
                                    }).addCompetitor({
                                        onSuccess: function() {
                                            $('#div_detail_frame_second').simpleTabs('refresh', 5);
                                        }
                                    }).addPartner({
                                        onSuccess: function() {
                                            $('#div_detail_frame_second').simpleTabs('refresh', 6);
                                        }
                                    }).addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_second div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_second div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    });
                                } else if (tabName == "contact") {
                                    uiPanel.detailPopupRn2({
                                        widgetName: 'contactDetail',
                                        selector: 'a.js_contact_name',
                                        target: '#div_detail_frame_third'
                                    }).showRecentAct({});

                                    $('#div_detail_frame_third').editable({
                                        isDigHole: true
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame_third').simpleTabs('refresh');
                                        }
                                    }).deleteContact().addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_third div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_third div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTeamMember();
                                } else if (tabName == "lead") {
                                    uiPanel.detailPopupRn3({
                                        widgetName: 'leadDetail',
                                        selector: 'a.js_lead_name',
                                        target: '#div_detail_frame_fouth'
                                    }).showRecentAct({});

                                    $('#div_detail_frame_fouth').editable({
                                        isDigHole: true
                                    }).addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_fouth div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_fouth div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame_fouth').simpleTabs('refresh');
                                        }
                                    }).deleteLead().transferLead().convertLead();
                                } else if (tabName == "partner") {
                                    uiPanel.detailPopupRn4({
                                        widgetName: 'partnerDetail',
                                        selector: 'a.js_partner_name',
                                        target: '#div_detail_frame_five'
                                    }).showRecentAct({});

                                    $('body').createOpportunity().createLead().createAccount().createContact().editBusiness().createContract().createCampaign().createCustomize().createOrder().createCase();

                                    $('#div_detail_frame_five').editable({
                                        isDigHole: true
                                    }).addTaskForSelf({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_five div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).addTaskForOther({
                                        onSuccess: function() {
                                            var $panel = $('#div_detail_frame_five div.js-panel-task');
                                            if ($panel.is(':visible')) {
                                                $panel.taskList();
                                            }
                                        }
                                    }).editVisibleItems({
                                        onSuccess: function() {
                                            $('#div_detail_frame_five').simpleTabs('refresh');
                                        }
                                    }).addTeamMember();
                                }
                            }

                            //翻页触发请求事件
                            me.element.find('[act="all_search_query_page_div"]').rkPaging({
                                maxGroupBtns: 7,
                                pagenum: data.pageNo || defaultPageNo, //（可选）当前页数，默认1
                                pagesize: data.pageSize || defaultPageSize, //（可选）当前每页显示条数，默认10
                                rowscount: data.totalCount, //所有数据数
                                onChange: function(pagenum) {
                                    me._fillPanelData(tabName, data.key, data.parentTabName, ui, pagenum, data.pageSize);
                                }
                            });

                        }
                    }
                }).fail(function(def, code, message) {
                    def.status != 0 && $.msg(rk.i18n('REQUEST_ERROR'));
                    return "";
                });
            }
        },

        _loadcrmdata: function(tab, panel, data) {
            data.wanxue = window.WANXUE;
            data.tenantId = SESSION.tenantId;
            data.setting = this.data.setting;

            var html = rk.templateText(require('page/tmpl/search/crmpanel.tpl'), {
                data: data,
                SESSION: SESSION
            });
            panel.html("");
            panel.html(html);
            tab.data('inited', false);

            var elem = this.element;
            elem.find('.fuzzy_result_div').beScroll();
        },
        _loaddynamicdata: function(tab, panel, keyword, pageNo, pageSize, tabName, parentTabName) {
            var elem = this.element;

            var arCallbacks = [];

            elem.find('div[act=global-search-tabs-2-content]').hide();
            elem.find('div[tabName=global-search-tabs-2-content-' + tabName + ']').show();

            elem.find('div[tabName=global-search-tabs-2-content-' + tabName + ']').beScroll({
                onTotalScroll: function() {
                    for (var i = 0, len = arCallbacks.length; i < len; i++) {
                        var fn = arCallbacks[i];
                        if ($.isFunction(fn)) {
                            fn();
                        }
                    }
                },
                onTotalScrollOffset: 120,
                alwaysTriggerOffsets: true
            });

            //var flag = ""
            require.async(["core/apps/feed/feed"], function() {
                elem.find('div[tabName=global-search-tabs-2-content-' + tabName + ']').feed2015({
                    tabs: [{
                        tabname: 'none',
                        //url: '/json/crm_search/all.action?key=' + keyword + "&pageNo=" + pageNo + "&pageSize=" + pageSize + "&tabName=" + tabName + "&parentTabName=" + parentTabName
                        url: '/json/crm_search/all.action?key=' + keyword /*+ "&pageSize=" + pageSize*/ + "&tabName=" + tabName + "&parentTabName=" + parentTabName,
                        appendmore: 'true'
                    }],
                    hasEditor: false,
                    scrollRegister: function(fn) {
                        arCallbacks.push(fn);
                    },
                    //数据加载完成
                    load: function(evt, arg) {
                        arg.panel.filter(':data(rk-feedflow)').feedflow(arg.pend + 'Feeds', arg.data.feeds);


                        messageCount = arg.data.messageCount;
                        fileCount = arg.data.fileCount;
                        blogCount = arg.data.blogCount;
                        praiseCount = arg.data.praiseCount;
                        questionCount = arg.data.questionCount;

                        //设置小tabtip数字
                        //elem.find("span[act=search-count]").show();
                        // console.log(this.data);
                        elem.find("span[act=dynamic_message_number]:eq(0)").text(messageCount);
                        elem.find("span[act=dynamic_file_number]:eq(0)").text(fileCount);
                        elem.find("span[act=dynamic_blog_number]:eq(0)").text(blogCount);
                        elem.find("span[act=dynamic_praise_number]:eq(0)").text(praiseCount);
                        elem.find("span[act=dynamic_question_number]:eq(0)").text(questionCount);
                        /* else if (tabName == "dynamic_file") {
                            fileCount = arg.data.fileCount;

                            elem.find("span[act=dynamic_file_number]:eq(0)").text(fileCount);
                        } else if (tabName == "dynamic_blog") {
                            blogCount = arg.data.blogCount;

                            elem.find("span[act=dynamic_blog_number]:eq(0)").text(blogCount);
                        } else if (tabName == "dynamic_praise") {
                            praiseCount = arg.data.praiseCount;

                            elem.find("span[act=dynamic_praise_number]:eq(0)").text(praiseCount);
                        } else if (tabName == "dynamic_question") {
                            questionCount = arg.data.questionCount;

                            elem.find("span[act=dynamic_question_number]:eq(0)").text(questionCount);
                        }*/

                        //如果无结果，展示没有与XX'+rk.i18n('search_no_query_1')+'
                        if ((tabName == "dynamic_message" && messageCount == 0) || (tabName == "dynamic_file" && fileCount == 0) || (tabName == "dynamic_blog" && blogCount == 0) || (tabName == "dynamic_praise" && praiseCount == 0) || (tabName == "dynamic_question" && questionCount == 0)) {
                            elem.find('div[tabName=global-search-tabs-2-content-' + tabName + ']').eq(0).html('<div class="oa-listview-default"><div class="ico"></div><p>' + rk.i18n('search_no_query') + '"' + keyword + '"' + rk.i18n('search_no_query_1') + '</p></div>');
                        }
                    }
                });
            });
            tab.data('inited', false);

            /*elem.find("span[act=dynamic_message_number]:eq(0)").text(messageCount);
            elem.find("span[act=dynamic_file_number]:eq(0)").text(fileCount);
            elem.find("span[act=dynamic_blog_number]:eq(0)").text(blogCount);
            elem.find("span[act=dynamic_praise_number]:eq(0)").text(praiseCount);
            elem.find("span[act=dynamic_question_number]:eq(0)").text(questionCount);*/

            //如果无结果，展示'+rk.i18n('search_no_query')+'XX'+rk.i18n('search_no_query_1')+'
            if ((tabName == "dynamic_message" && messageCount == 0) || (tabName == "dynamic_file" && fileCount == 0) || (tabName == "dynamic_blog" && blogCount == 0) || (tabName == "dynamic_praise" && praiseCount == 0) || (tabName == "dynamic_question" && questionCount == 0)) {
                elem.find('div[tabName=global-search-tabs-2-content-' + tabName + ']').eq(0).html('<div class="oa-listview-default"><div class="ico"></div><p>' + rk.i18n('search_no_query') + '"' + keyword + '"' + rk.i18n('search_no_query_1') + '</p></div>');
            }

            //elem.find('div[act=rk-dynamic-list-global-search]').beScroll();
        },
        _loadtopicdata: function(tab, panel, keyword, pageNo, pageSize, tabName, parentTabName) {
            var elem = this.element;
            var arCallbacks = [];

            elem.find("div[id=global-search-tabs-3-content]").beScroll({
                onTotalScroll: function() {
                    for (var i = 0, len = arCallbacks.length; i < len; i++) {
                        var fn = arCallbacks[i];
                        if ($.isFunction(fn)) {
                            fn();
                        }
                    }
                },
                onTotalScrollOffset: 120,
                alwaysTriggerOffsets: true
            });

            require.async(["core/apps/feed/feed"], function() {
                elem.find("[id='global-search-tabs-3-content']").feed2015({
                    tabs: [{
                        tabname: 'none',
                        //url: '/json/crm_search/all.action?key=' + keyword + "&pageNo=" + pageNo + "&pageSize=" + pageSize + "&tabName=" + tabName + "&parentTabName=" + parentTabName,
                        url: '/json/crm_search/all.action?key=' + keyword /*+ "&pageSize=" + pageSize*/ + "&tabName=" + tabName + "&parentTabName=" + parentTabName,
                        appendmore: 'true'
                    }],
                    hasEditor: false,
                    scrollRegister: function(fn) {
                        arCallbacks.push(fn);
                    },
                    //数据加载完成
                    load: function(evt, arg) {
                        arg.panel.filter(':data(rk-feedflow)').feedflow(arg.pend + 'Feeds', arg.data.feeds);

                        //设置共XX项搜索结果
                        elem.find("span[act=search-count]").show();
                        elem.find("span[act=search-count-number]:eq(0)").text(arg.data.feeds.length);

                        //如果无结果，展示'+rk.i18n('search_no_query')+'XX'+rk.i18n('search_no_query_1')+'
                        if (arg.data.feeds.length == 0) {
                            elem.find("[id='global-search-tabs-3-content']").eq(0).html('<div class="oa-listview-default"><div class="ico"></div><p>' + rk.i18n('search_no_query') + '"' + keyword + '"' + rk.i18n('search_no_query_1') + '</p></div>');
                        }

                        //elem.find('div[id=global-search-tabs-3-content]').beScroll();
                    }
                });
            });
            tab.data('inited', false);
        },

        _dataFormatBeforeShow: function($data, tabName) {
            if (tabName == "account") {
                if ($data.accounts) {
                    var levelOptions = new Array();
                    var highSeaIdOptions = new Array();
                    for (var o, i = 0, len = $data.items.length; i < len; i++) {
                        o = $data.items[i];
                        if (o.entryPropertyNameOnly == 'level') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                levelOptions[o.options[i].id] = o.options[i].name;
                            }
                        } else if (o.entryPropertyNameOnly == 'highSeaId') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                highSeaIdOptions[o.options[i].id] = o.options[i].name;
                            }
                        }
                    }
                    for (var i in $data.accounts) {
                        $data.accounts[i].level = levelOptions[$data.accounts[i].level];
                        //$data.accounts[i].highSeaId = highSeaIdOptions[$data.accounts[i].highSeaId];
                        $data.accounts[i].createdAt = Globalize.format(new Date($data.accounts[i].createdAt - 0), 'yyyy-MM-dd');
                        if ($data.accounts[i].highSeaId != "") {
                            if ($data.highSeaList[$data.accounts[i].highSeaId])
                                $data.accounts[i].highSeaId = $data.highSeaList[$data.accounts[i].highSeaId].name;
                        }

                        if ($data.users && $data.users[$data.accounts[i].ownerId]) {
                            $data.accounts[i].ownerIcon = $data.users[$data.accounts[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            $data.accounts[i].ownerName = $data.users[$data.accounts[i].ownerId].name;
                        } else {
                            $data.accounts[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            $data.accounts[i].ownerName = "";
                        }
                        //分众屏蔽掉客户所有人
                        if (SESSION.pcCode == 100) {
                            $data.accounts[i].ownerName = "";
                        }
                    }
                }
            } else if (tabName == "opportunity") {
                if ($data.opportunities) {
                    var opportunityTypeOptions = new Array();
                    for (var o, i = 0, len = $data.items.length; i < len; i++) {
                        o = $data.items[i];
                        if (o.entryPropertyNameOnly == 'opportunityType') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                opportunityTypeOptions[o.options[i].id] = o.options[i].name;
                            }
                        }
                    }

                    for (var i in $data.opportunities) {
                        $data.opportunities[i].createdAt = Globalize.format(new Date($data.opportunities[i].createdAt - 0), 'yyyy-MM-dd');
                        $data.opportunities[i].closeDate = Globalize.format(new Date($data.opportunities[i].closeDate - 0), 'yyyy-MM-dd');
                        if ($data.opportunities[i].opportunityType == "") {
                            $data.opportunities[i].opportunityType = "";
                        } else {
                            //$data.opportunities[i].opportunityType = $data.opportunityTypeList[$data.opportunities[i].opportunityType].typeName;
                            $data.opportunities[i].opportunityType = opportunityTypeOptions[$data.opportunities[i].opportunityType];
                        }

                        //解析销售阶段
                        if ($data.dummyItemValuesMap['saleStageId'].dummyItemValues[$data.opportunities[i].saleStageId] == undefined) {
                            $data.opportunities[i].saleStageId = "";
                        } else {
                            $data.opportunities[i].saleStageId = $data.dummyItemValuesMap['saleStageId'].dummyItemValues[$data.opportunities[i].saleStageId].value;
                        }

                        if ($data.users && $data.users[$data.opportunities[i].ownerId]) {
                            $data.opportunities[i].ownerIcon = $data.users[$data.opportunities[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            $data.opportunities[i].ownerName = $data.users[$data.opportunities[i].ownerId].name;
                        } else {
                            $data.opportunities[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            $data.opportunities[i].ownerName = "";
                        }

                        if ($data.opportunities[i].money) {
                            $data.opportunities[i].money = ($data.opportunities[i].money - 0).toFixed(2);
                        }
                        //    //var string = numeral(1000).format('0,0');
                        //    $data.opportunities[i].money = numeral($data.opportunities[i].money).format('0,0');
                    }
                }
            } else if (tabName == "lead") {
                if ($data.leads) {
                    var statusOptions = new Array();
                    for (var o, i = 0, len = $data.items.length; i < len; i++) {
                        o = $data.items[i];
                        if (o.entryPropertyNameOnly == 'status') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                statusOptions[o.options[i].id] = o.options[i].name;
                            }
                        }
                    }
                    for (var i in $data.leads) {
                        $data.leads[i].createdAt = Globalize.format(new Date($data.leads[i].createdAt - 0), 'yyyy-MM-dd');
                        //解析跟进状态
                        //$data.leads[i].status = $data.leadStatusList[$data.leads[i].status].selectItemName;
                        $data.leads[i].status = statusOptions[$data.leads[i].status];
                        if ($data.leads[i].highSeaId != "")
                            $data.leads[i].highSeaId = $data.highSeaList[$data.leads[i].highSeaId].name;

                        if ($data.users && $data.users[$data.leads[i].ownerId]) {
                            $data.leads[i].ownerIcon = $data.users[$data.leads[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            $data.leads[i].ownerName = $data.users[$data.leads[i].ownerId].name;
                        } else {
                            $data.leads[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            $data.leads[i].ownerName = "";
                        }
                    }
                }
            } else if (tabName == "contact") {
                if ($data.contacts) {
                    for (var i in $data.contacts) {
                        $data.contacts[i].createdAt = Globalize.format(new Date($data.contacts[i].createdAt - 0), 'yyyy-MM-dd');

                        if ($data.users && $data.users[$data.contacts[i].ownerId]) {
                            $data.contacts[i].ownerIcon = $data.users[$data.contacts[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            $data.contacts[i].ownerName = $data.users[$data.contacts[i].ownerId].name;
                        } else {
                            $data.contacts[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            $data.contacts[i].ownerName = "";
                        }
                    }
                }
            } else if (tabName == "partner") {
                if ($data.partners) {
                    var partnerLevelOptions = new Array();
                    var highSeaIdOptions = new Array();
                    for (var o, i = 0, len = $data.items.length; i < len; i++) {
                        o = $data.items[i];
                        if (o.entryPropertyNameOnly == 'partnerLevel') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                partnerLevelOptions[o.options[i].id] = o.options[i].name;
                            }
                        } else if (o.entryPropertyNameOnly == 'highSeaId') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                highSeaIdOptions[o.options[i].id] = o.options[i].name;
                            }
                        }
                    }
                    for (var i in $data.partners) {
                        $data.partners[i].partnerLevel = partnerLevelOptions[$data.partners[i].partnerLevel];
                        //$data.partners[i].highSeaId = highSeaIdOptions[$data.partners[i].highSeaId];
                        $data.partners[i].createdAt = Globalize.format(new Date($data.partners[i].createdAt - 0), 'yyyy-MM-dd');
                        if ($data.partners[i].highSeaId != "") {
                            if ($data.highSeaList[$data.partners[i].highSeaId])
                                $data.partners[i].highSeaId = $data.highSeaList[$data.partners[i].highSeaId].name;
                        }

                        if ($data.users && $data.users[$data.partners[i].ownerId]) {
                            $data.partners[i].ownerIcon = $data.users[$data.partners[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            $data.partners[i].ownerName = $data.users[$data.partners[i].ownerId].name;
                        } else {
                            $data.partners[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            $data.partners[i].ownerName = "";
                        }
                    }
                }
            } else if (tabName == "agent") {
                if ($data.agents && $data.agents.length > 0) {
                    var tableList = $data.agents;
                    var levelOptions = new Array();
                    var highSeaIdOptions = new Array();
                    for (var o, i = 0, len = $data.items.length; i < len; i++) {
                        o = $data.items[i];
                        if (o.entryPropertyNameOnly == 'level') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                levelOptions[o.options[i].id] = o.options[i].name;
                            }
                        } else if (o.entryPropertyNameOnly == 'highSeaId') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                highSeaIdOptions[o.options[i].id] = o.options[i].name;
                            }
                        }
                    }
                    for (var i in tableList) {
                        tableList[i].level = levelOptions[tableList[i].level];
                        //$data.accounts[i].highSeaId = highSeaIdOptions[$data.accounts[i].highSeaId];
                        tableList[i].createdAt = Globalize.format(new Date(tableList[i].createdAt - 0), 'yyyy-MM-dd');
                        if (tableList.highSeaId != "") {
                            if ($data.highSeaList[tableList[i].highSeaId])
                                tableList[i].highSeaId = $data.highSeaList[tableList[i].highSeaId].name;
                        }

                        if ($data.users && $data.users[tableList[i].ownerId]) {
                            tableList[i].ownerIcon = $data.users[tableList[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            tableList[i].ownerName = $data.users[tableList[i].ownerId].name;
                        } else {
                            tableList[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            tableList[i].ownerName = "";
                        }
                    }
                }
            } else if (tabName == "terminal") {
                if ($data.terminals && $data.terminals.length > 0) {
                    var tableList = $data.terminals;
                    var levelOptions = new Array();
                    var highSeaIdOptions = new Array();
                    for (var o, i = 0, len = $data.items.length; i < len; i++) {
                        o = $data.items[i];
                        if (o.entryPropertyNameOnly == 'level') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                levelOptions[o.options[i].id] = o.options[i].name;
                            }
                        } else if (o.entryPropertyNameOnly == 'highSeaId') {
                            for (var i = 0, len = o.options.length; i < len; i++) {
                                highSeaIdOptions[o.options[i].id] = o.options[i].name;
                            }
                        }
                    }
                    for (var i in tableList) {
                        tableList[i].level = levelOptions[tableList[i].level];
                        tableList[i].createdAt = Globalize.format(new Date(tableList[i].createdAt - 0), 'yyyy-MM-dd');
                        if (tableList.highSeaId != "") {
                            if ($data.highSeaList[tableList[i].highSeaId])
                                tableList[i].highSeaId = $data.highSeaList[tableList[i].highSeaId].name;
                        }

                        if ($data.users && $data.users[tableList[i].ownerId]) {
                            tableList[i].ownerIcon = $data.users[tableList[i].ownerId].icon || DEFAULTS.USER_DEFAULT_ICON;
                            tableList[i].ownerName = $data.users[tableList[i].ownerId].name;
                        } else {
                            tableList[i].ownerIcon = DEFAULTS.USER_DEFAULT_ICON;
                            tableList[i].ownerName = "";
                        }
                    }
                }
            }
        }
    });
});
